from time import sleep

from pages.BasePage import BasePage
from locator.home_locator.HomeLocators import HomeLocator


class HomePage(BasePage):

    # 用户头像是否存在
    def is_exist(self):
        path = "腾讯文档_主页"
        return self.wait_element_presence(locator=HomeLocator.userImage, path=path)

    # 在线办公教育
    def online_edu(self):
        path = "在线办公教育"
        self.click_element(locator=HomeLocator.online_edu, path=path)

    # 获取页面URL
    def get_title(self, name):
        path = "在线办公教育_页面标题"
        self.switch_to_window_handle(flag="title", name=name)
        sleep(3)
        title = self.get_browserTitle(path=path)
        sleep(2)
        self.close_window_handle(path=path)
        return title

    # 切回腾讯文档首页
    def switch_home_handle(self, name):
        path = "腾讯文档_首页"
        self.switch_to_window_handle(flag="title", name=name)

    # 选择文件并右键打开功能按钮，点击复制链接
    def select_file(self):
        path = "腾讯文档_文件操作"
        self.action_chains_right_click(locator=HomeLocator.fileName, path=path)
        self.click_element(locator=HomeLocator.copyUrl, path=path)

    # 点击文件列表页，文件所在行的复制链接按钮
    def get_file_url(self):
        path = "文件列表页_复制链接"
        self.action_chains_move_element(locator=HomeLocator.fileName, path=path)
        self.click_element(locator=HomeLocator.file_line_copy_url, path=path)

    # 获取提示信息
    def get_message(self):
        path = "腾讯文档_获取提示信息"
        return self.get_element_text(locator=HomeLocator.centerMessage, path=path)
